<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>登录</title>
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="/css/login.css"/>

</head>
<body >
<div class="align layui-word-aux #c2c2c2">
    <div class="layui-col-lg-offset4">
        <br/><br/><br/>
    <div  style="width: 600px;font-weight: bolder; font-size: large; margin-top: 40px; margin-left: 110px; margin-right: auto">Woda   Project   and   service   management   system</div>
    </div>
    <br/><br/><br/><br/><br/>
    <div class="section">
        <div class="all">
            <div class="nav">
                <a class="login on">管理员登录</a>
                <a class="login">普通用户登录</a>
            </div>
            <div class="contentbox">
                <div class="box active">
                    <div class="cont-1">
                        <br/> <br/><br/><br/>
                        <input  name="username" type="text" placeholder="用户名"/>
                        <input  name="password" type="password" placeholder="密码"/>
                        <button type="reset" class="btn" lay-filter="login_bt" id="login_bt" lay-submit="">登&nbsp;&nbsp;陆</button>
                    </div>
                </div>
                <div class="box">
                    <div class="cont-2">
                        <br/>
                        注意：<br/>
                            此方式登录您只有查看和申请权限，若需要其他权限，请切换至用户名密码登录
                        <br/><br/><br/><br/>
                        <button type="reset" class="btn" onclick="one()">一键登录</button>
                    </div>
                </div>
            </div>
        </div>
    </div>




</div>
<script>
    $().ready(function(){
        $(function(){
            $(".nav a").off("click").on("click",function(){
                var index = $(this).index();
                $(this).addClass("on").siblings().removeClass("on");
                $(".contentbox .box").eq(index).addClass("active").siblings().removeClass("active");
            });
        });
    })
</script>
<script>
    function one(){
        loadPage("/server/baseServer")
    }
    function loadPage(url) {
        window.location.href = url;
    }
    function serializeObject(form){
        var o ={};
        $.each(form.serializeArray(),function(index){
            if(o[this['name']]){
                o[this['name']] = o[this['name']] +","+this['value'];

            }else{
                o[this['name']] = this['value'];
            }
        });
        return o;
    }
    layui.use('form', function(){
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(login_bt)', function(data){
            var a = document.getElementById("username").value;
            var from= $("#Login_form");
            var model= serializeObject(from);

            $.ajax({
                type: "post",
                url: "/server/userLogin",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(model),
                dataType: "json",
                success:function(data) {
                    if (data =="fail") {
                        layer.alert("用户名密码错误")
                    }else {
                       var storage = window.localStorage;
                        storage.clear();
                        storage["user"] = data;

                        storage["username"] =a ;
                        loadPage("/server/baseServer");
                    };
                }
            })
        });
    });
</script>
</body>
</html>